<?php
	class Login_model extends CI_Model{
	
	
/*--------------Dang ky tai khoan--------------------*/	
		function insert_tk($data)
		{
			
			$this->db->insert("taikhoan",$data);
			return $this->db->insert_id();
		}
		function check_username($id)
		{
			$this->db->where("ten_tk",$id);
			$this->db->where("quyen",2);
		
			$taikhoan = $this->db->get("taikhoan");
			return $taikhoan->row();
			}
		function check_email($email)
		{
			$this->db->select("email");
			$this->db->where("email",$email);
			$this->db->where("quyen",2);
			
			$taikhoan = $this->db->get("taikhoan");
			return $taikhoan->row();
			}
		
		public function tk_khachhang($ten_tk)
		{
			$this->db->where("ten_tk",$ten_tk);
			$this->db->where("active_email", 1);
			
			$taikhoan = $this->db->get("taikhoan");
			return $taikhoan->row();
		}
		public function get_mat_khau_quen($ten_tk)
		{
			$this->db->where("ten_tk",$ten_tk);			
			$data=$this->db->get("taikhoan");
			return $data->row_array();
		}	
		public function checkActive($ten_tk, $ma_kich_hoat)
		{
			$this->db->where("ten_tk",$ten_tk);
			$this->db->where("md5(ma_kich_hoat)",$ma_kich_hoat);
			$taikhoan = $this->db->get("taikhoan");
			return $taikhoan->row_array();
		}
		
		public function capnhat_tk_active($ten_tk,$data)
		{
			$this->db->where("ten_tk",$ten_tk);
			$this->db->update("taikhoan",$data);
		}
		function thongtincanhan_admin($user)
		{
		   $this->db->where("ten_tk",$user);
		   $this->db->where("quyen",1);
		   
		   $data = $this->db->get("taikhoan");
		   return $data->row();

		}
	
	/*-----------------Dang nhap-----------------*/
	function check_email_username($username,$email)
		{
			$this->db->where("ten_tk",$username);
			$this->db->where("email",$email);
			$this->db->where("quyen",2);
			$this->db->where("trang_thai",1);
			$taikhoan = $this->db->get("taikhoan");
			return $taikhoan->row();
			}
	}
?>